from pox.core import core
from pox.lib.util import dpid_to_str

log = core.getLogger()

class MyComponent(object):
	def __init__(self):
		core.openflow.addListeners(self)
	
	def _handle_ConnectionUp(self,event):
            log.debug("Switch %s has come up.",dpid_to_str(event.dpid))

        def _handle_ConnectionDown(self,event):
            log.debug("Switch went down")

        def _handle_PortStatus(self,event):
            if event.added:
                action = "added"
            elif event.deleted:
                action = "removed"
            else:
                action = "modified"
            print "Port %s on Switch %s has been %s" %(event.port, event.dpid, action)

        def _handle_PacketIn(self,event):
            log.debug("Received packet  port %s data %s", event.port, event.data)

def launch():
	core.registerNew(MyComponent)
